package com.ytjj.qmyx.data.amqp.consumer;

import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.ClickStatisticsDto;
import com.ytjj.qmyx.data.service.ClickStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *
 *  *
 **/
@Slf4j
@Component
public class ClickStatisticsListener {

    @Resource
    private ClickStatisticsService clickStatisticsService;

    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.CLICK_STATISTICS_QUEUE, durable = "true"))
    public void clickStatistics(ClickStatisticsDto clickStatisticsDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
        log.debug("点击统计消息：\n{}",clickStatisticsDto);
        try {
            clickStatisticsService.clickStatistics(clickStatisticsDto);
        } catch (Exception e) {
            log.error("点击统计消息失败：\n{}",clickStatisticsDto);
        }
    }
}
